# Based on Arch's PKGBUILD

_realname=tclvfs
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}-cvs
pkgver=20130425
pkgrel=3
pkgdesc="Virtual Filesystem support for Tcl"
arch=('any')
url="https://sourceforge.net/projects/tclvfs/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-tcl")
makedepends=('cvs')
provides=("${MINGW_PACKAGE_PREFIX}-tclvfs")
conflicts=("${MINGW_PACKAGE_PREFIX}-tclvfs")
source=('001-fix-detect-mingw.patch')
# generate with 'makepkg -g'
sha256sums=('508dc305536f29023a6142056b6729617c2e3d93f5b86054128a7b7688ec9344')

_cvsroot=":pserver:anonymous:@tclvfs.cvs.sourceforge.net:/cvsroot/tclvfs"
_cvsmod="${_realname}"

_build="${srcdir}/$_cvsmod-build${CARCH}"

prepare() {
  cd "${srcdir}"
  msg "Connecting to $_cvsmod.sourceforge.net CVS server...."
  if [ -d $_cvsmod/CVS ]; then
    cd $_cvsmod
    cvs -z3 update -d
  else
    cvs -z3 -d $_cvsroot co -D ${pkgver} -f $_cvsmod
  fi

  msg "CVS checkout done or server timeout"

  cd "${srcdir}/tclvfs"

  # If "configure" has been patched by a previous build, revert it or
  # `patch' will fail:
  cvs update -C configure

  patch -p1 -i ${srcdir}/001-fix-detect-mingw.patch
}

build() {
  msg "Starting build..."

  rm -rf "${_build}"
  cp -r "${srcdir}/${_cvsmod}" "$_build"

  cd "${_build}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --mandir=${MINGW_PREFIX}/share/man
  make
}

package() {
  cd "${_build}"
  make DESTDIR="${pkgdir}" install
}
